package com.wangjinhai.provider;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Servlet;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2018/8/14.
 * @Modified By:
 */
@Configuration
public class HystrixDashboardConfiguration {

    /**
     * 注册servlet
     */
    @Bean
    public ServletRegistrationBean servletRegistrationBean()
    {
        //创建HystrixMetricsStreamServlet
        HystrixMetricsStreamServlet streamServlet=new HystrixMetricsStreamServlet();
        //注册Servlet
        ServletRegistrationBean registrationBean = new ServletRegistrationBean<Servlet>(streamServlet);
        //设置加载顺序
        registrationBean.setLoadOnStartup(1);
        //设置访问地址
        registrationBean.addUrlMappings("/hystrix.stream");
        //设置Servlet名称
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }
}
